//计数器示例
import 'package:flutter/material.dart';



class DemoCounter extends StatefulWidget {
  DemoCounter({Key key, this.title,this.initValue:1}) : super(key: key);
  final String title;
  final int initValue;

  @override
  State<StatefulWidget> createState() {
    return new _MyHomePageState();
  }
}

class _MyHomePageState extends State<DemoCounter> {
  int _counter;

  @override
  void initState(){
    super.initState();
    _counter=widget.initValue;
    print("initState");
  }

  void _add() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    print("build");
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text('you have pushed the button this many times'),
            new Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _add,
        tooltip: '+1',
        child: new Icon(Icons.add),
      ),
    );
  }

  @override
  void didUpdateWidget(DemoCounter oldWidget) {
    super.didUpdateWidget(oldWidget);
    print("didUpdateWidget");
  }

  @override
  void deactivate() {
    super.deactivate();
    print("deactivate");
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("reassemble");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("didChangeDependencies");
  }
}
